package lib.bone.nepudata.service.impl;

import lib.bone.common.constant.ResponseCodeConst;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.common.exception.BusinessException;
import lib.bone.nepudata.dao.NepuOvertimeProjectDAO;
import lib.bone.nepudata.domain.entity.NepuOvertimeProject;
import lib.bone.nepudata.service.NepuOvertimeProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class NepuOvertimeProjectServiceImpl implements NepuOvertimeProjectService {

    @Autowired
    NepuOvertimeProjectDAO dao;

    @Override
    public NepuOvertimeProject saveOne(NepuOvertimeProject project) {
        List<NepuOvertimeProject> projects = dao.findByLinkId(project.getLinkId());
        if (projects.size() > 0){
            throw new BusinessException(ResponseCodeConst.BAD_REQUEST,"存在重复记录");
        }
        return dao.save(project);
    }

    @Override
    public NepuOvertimeProject getByLinkId(String linkId) {
        List<NepuOvertimeProject> projects = dao.findByLinkId(linkId);
        if (projects.size() == 0){
            return null;
        }
        return projects.get(0);
    }

    @Override
    public List<NepuOvertimeProject> getAll() {
        return dao.findAll();
    }
}
